/* *
 * FTL中F7配置方式
 * 
 *<label id="对应F7的ID" f7Url="F7页面的URL" width="打开F7窗口的宽度" height="打开F7页面的高度" title="打开的F7窗口标题" >
 *	<input f7="value" name="assessPeriod.id" id="assessPeriod.id" type="hidden" readOnly="readOnly" />
 *	<input f7="name" name="assessPeriod.name" id="assessPeriod.name" type="text" readOnly="readOnly" ondblclick="openF7('对应F7的ID')"/>
 *	<strong onclick="clearF7('对应F7的ID')"></strong>
 *	<span class="p_hov" onclick="openF7('对应F7的ID')"></span>
 *</label>
 *
 * */
function openF7(id){
	var f7 = getF7Instance(id);
	if(f7 && !f7.disabled){
		f7.show();
	}
}
function openPositionTypeLevelF7(id){
	var longNumber = $("#hiddenId").val();
	var url = $("#"+id).attr("f7Url");
	var urls = url.split('?');
	url = urls[0];
	url = url + '?otherParams=POSITIONTYPELEVELORGLONGNUMBER' + longNumber;
	$("#"+id).attr("f7Url",url);
	var f7 = getF7Instance(id);
	if(f7 && !f7.disabled){
		f7.show();
	}
}
function openPositionTypeF7(id){
	var orgId = $("input[key='orgIdForPositionType']").val();
	var url = $("#"+id).attr("f7Url");
	var urls = url.split('?');
	url = urls[0];
	url = url + '?otherParams=POSITIONTYPE' + orgId;
	$("#"+id).attr("f7Url",url);
	var f7 = getF7Instance(id);
	if(f7 && !f7.disabled){
		f7.show();
	}
}
function clearF7(id){
	var f7 = getF7Instance(id);
	if(f7 && !f7.disabled){
		f7.clear();
	}
}
function getF7Instance(id){
	var f7 = new F7(id);
	return f7;
}
var currentF7;
function returnF7Value(value){
	if(currentF7 && currentF7 != null){
		currentF7.setValue(value);
	}
}
function F7(id){
	return this.create(id);
}
F7.prototype.create = function(id){
	this.f7id = id;
	this.doc = $('#'+id);
	this.url = this.doc.attr('f7Url');
	this.title = this.doc.attr('title');
	this.width = this.doc.attr('width');
	this.height = this.doc.attr('height');
	this.isMultiple = this.doc.attr('isMultiple');
	this.disabled = this.doc.attr('disabled')=='disabled'?true:false;
	this.setDisabled(this.disabled);
	this.onValueChange = this.doc.attr('onchange');
	this.oldValue = null;
	this.value = null;;
	var id = this.doc.find('input[f7="value"]').val();
	var name =this.doc.find('input[f7="name"]').val();
	if(id != null && id != ''){
		this.oldValue = {'id':id,'name':name};
		this.value = this.oldValue;
	}
	return this;
}
F7.prototype.show = function(){
	if(this.doc.attr('returnFunName')){
		art.dialog.data('returnFunName',this.doc.attr('returnFunName'));
	}else{
		art.dialog.data('returnFunName','returnF7Value');
	}
	var winName = window.name;
	if(winName && winName.indexOf('Open')==0){
		art.dialog.data('iframeId',winName.replace('Open',''));
	}
	currentF7 = this;
	art.dialog.open(this.url,
			{id:this.f7id,
			 title: this.title,
			 width:this.width,
			 height:this.height,
			 lock: true
			 }
	);
}
F7.prototype.setValue = function(value){
	var iframeId = art.dialog.data('iframeId')
	art.dialog.removeData('iframeId');
	var newValue = value;
	if(value && value != null){
		if(value && value.length){//如果是数组
			//传过来的是数组
			if(this.isMultiple){
				//当前为多选F7
				var vs = "";
				var ns = "";
				for(var i = 0; i < value.length; i++){
					vs = (vs==""?value[i].id:vs+";"+value[i].id);
					ns = (ns==""?value[i].name:ns+";"+value[i].name)
				}
				this.doc.find('input[f7="value"]').val(vs);
				this.doc.find('input[f7="name"]').val(ns);
			}else{
				this.doc.find('input[f7="value"]').val(value[0].id);
				this.doc.find('input[f7="name"]').val(value[0].name);
				newValue = value[0];
			}
		}else{
			//传来的是非数组，或者数组长度为0
			this.doc.find('input[f7="value"]').val(value.id);
			this.doc.find('input[f7="name"]').val(value.name);
			if(value&&value.longNumber){
				$("#hiddenId").val(value.longNumber);
			}
			if(this.isMultiple){
				newValue = new Array();
				newValue.push(value);
			}
		}
	}else{
		this.doc.find('input[f7="value"]').val("");
		this.doc.find('input[f7="name"]').val("");
	}
	this.oldValue = this.value;
	this.value = newValue;
	if(this.onValueChange && this.onValueChange != '' && this.onValueChange != null){
		if(iframeId){
			var iframe1 = $(self.parent.document).find("iframe[name='Open"+iframeId+"']").get(0);
			iframe1.contentWindow[this.onValueChange].call(null,this.oldValue,newValue,this.doc);
		}else{
			window[this.onValueChange].call(null,this.oldValue,newValue,this.doc);
		}
	}
}
F7.prototype.clear = function(){
	this.setValue(null);
}
F7.prototype.setDisabled = function(disabled){
	if(true == disabled){
		this.doc.find('input[f7]').attr('disabled','disabled');
	}else{
		this.doc.find('input[f7]').removeAttr('disabled');
	}
	this.disabled = disabled;
}
